#!/usr/bin/python
# -*- coding: utf-8 -*-

#-------------------------------------------------
#Create At: 2009-1-14 下午10:04:20 
#Create By: Fla.sam
#
#DESC: 
#
#-------------------------------------------------

from os import environ
environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from settings import *

from django_extensions.db.fields import AutoSlugField
import uuid
from urlify import urlify



class ZhAutoSlugField(AutoSlugField):
    
    def __init__(self, *args, **kwargs):
        kwargs.setdefault('blank', True)
        kwargs.setdefault('editable', False)

        populate_from = kwargs.pop('populate_from', None)
        if populate_from is None:
            raise ValueError("missing 'populate_from' argument")
        else:
            self._populate_from = populate_from
        self.separator = kwargs.pop('separator',  u'-')
        self.overwrite = kwargs.pop('overwrite', True)
        super(AutoSlugField, self).__init__(*args, **kwargs)
        
    def _slug_strip(self, value):
        pass
    
    def create_slug(self, model_instance, add):
        # get fields to populate from and slug field to set
        populate_field = model_instance._meta.get_field(self._populate_from)
        slug_field = model_instance._meta.get_field(self.attname)
        if add or self.overwrite:
            # slugify the original field content and set next step to 2
            slug = urlify.urlify(getattr(model_instance, populate_field.attname))
            
        return slug
            
def mk_key( s = None ):
    '''
    make a unique key
    @param s:
    '''
    if s :
        return str( uuid.uuid3( uuid.NAMESPACE_DNS, s ) ).replace( '-', '' )
    else:
        return str( uuid.uuid1() ).replace( '-', '' )
    
    
def u2m( u_point ):
    '''
    U point to Money
    @param u_point:
    '''
    pass

def m2u( money ):
    '''
    Money to U point
    @param money:
    '''
    pass

def main():
    print mk_key()
    
    
if __name__ == '__main__':
    main()
